package com.hq.ims.data.vo;

import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.CompanyDepartment;
import com.hq.ims.data.utils.ErrMsgConstant;
import com.hq.ims.data.vo.auth.BaseRowAuthVo;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 蒋柏平
 * @since 20240927
 */
@Mapper
public interface CompanyDepartmentMapstruct {

    CompanyDepartmentMapstruct INSTANCE = Mappers.getMapper(CompanyDepartmentMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    CompanyDepartmentVo toCompanyDepartmentVoVo(CompanyDepartment source);

    default List<CompanyDepartmentVo> toCompanyDepartmentVoList(List<CompanyDepartment> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toCompanyDepartmentVoVo).collect(Collectors.toList());
    }

    //-------------------------------- 转换VO类 --------------------------------


    @Mappings({
    })
    SimpleCompanyDepartmentVo toSimpleCompanyDepartmentVo(CompanyDepartment source);

    default List<SimpleCompanyDepartmentVo> toSimpleCompanyDepartmentVoList(List<CompanyDepartment> source) {
        if (source == null) {
            return new ArrayList<>(0);
        }
        return source.stream().map(this::toSimpleCompanyDepartmentVo).collect(Collectors.toList());

    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class CompanyDepartmentVo extends CompanyDepartment {

        @ApiModelProperty(value = "用户列表")
        private List<UserMapstruct.UserAndCompanySimpleVo> userList;

        @ApiModelProperty(value = "用户数量")
        private Integer userAmount;

    }

    @ApiModel(value = "简单的部门对象")
    @Data
    class SimpleCompanyDepartmentVo {

        @ApiModelProperty(value = "公司部门ID")
        private String companyDepartmentId;

        @ApiModelProperty(value = "公司部门名称")
        private String companyDepartmentName;

        @ApiModelProperty(value = "用户列表")
        private List<UserMapstruct.UserAndCompanySimpleVo> userList;

    }

    @ApiModel(value = "用户加入部门")
    @Data
    class UserJoinDepartment {

        @NotBlank(message = ErrMsgConstant.DEPARTMENT_INFO_NOT_EXISTS)
        @ApiModelProperty(value = "公司部门ID")
        private String companyDepartmentId;

        @NotEmpty(message = ErrMsgConstant.USER_NOT_EMPTY)
        @ApiModelProperty(value = "用户ID")
        private String userId;

    }

    @ApiModel(value = "行级权限对象")
    @Data
    class CompanyDepartmentRowAuthVo extends BaseRowAuthVo {

        //自定义其它行级权限


        //构造函数
        public CompanyDepartmentRowAuthVo(CompanyDepartment entity) {
            //当前操作用户ID
            String userId = AppUtils.getUserId();
        }

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

        @NotBlank(message = "数据ID不能为空", groups = {VdEdit.class})
        @ApiModelProperty(value = "数据ID")
        private String companyDepartmentId;

        @NotBlank(message = "公司ID不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "公司ID长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "公司ID")
        private String companyId;

        @NotBlank(message = "部门名称不能为空", groups = {VdAdd.class, VdEdit.class})
        @Size(min = 1, max = 255, message = "部门名称长度不能超过255", groups = {VdAdd.class, VdEdit.class})
        @ApiModelProperty(value = "部门名称")
        private String companDepartmentName;


    }

    @ApiModel(value = "设置部门负责人")
    @Data
    class SetDepartmentPrincipal {

        @NotBlank(message = "数据ID不能为空")
        @ApiModelProperty(value = "数据ID")
        private String companyDepartmentId;

        @NotBlank(message = "用户不能为空")
        @ApiModelProperty(value = "用户不能为空")
        private String userId;

        @ApiModelProperty(value = "是否负责人")
        private Boolean isPrincipal = false;

    }

    @ApiModel(value = "为部门绑定权限")
    @Data
    class BindCompanyDepartmentAuth {

        @NotBlank(message = "数据ID不能为空")
        private String companyDepartmentId;

        @NotEmpty(message = "权限不能为空")
        private List<String> permissionAuthorityIdList;

    }

    //-------------------------------- springboot验证标识 --------------------------------

}
